package com.lihonghao.controller.netty;

import cn.hutool.json.JSONUtil;
import com.lihonghao.consts.HTTP;
import com.lihonghao.gateway.ControllerNetty;
import com.lihonghao.gateway.Router;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@ControllerNetty
public class HelloWorldController {
    @Router(path = "/")
    public String index() {
        return "index";
    }

    @Router(path = "/hello")
    public String helloWorld() {
        Map data = Collections.synchronizedMap(new HashMap<>());
        for (int i = 0;i<1000;i++)
            data.put("key"+i, "value"+i);
        return JSONUtil.toJsonStr(data);
    }

    @Router(path = "/hello",method = HTTP.Method.POST)
    public String helloPost() {
        Map data = Collections.synchronizedMap(new HashMap<>());
        for (int i = 0;i<1000;i++)
            data.put("key"+i, "value"+i);
        return JSONUtil.toJsonStr(data);
    }
}
